package com.example.mygesture;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;



import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.Toast;

public class GA extends Activity {
    private GestureDetector mDector;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gesture);
        mDector=new GestureDetector(this, new GestureDetector.SimpleOnGestureListener(){

            public boolean onFling(MotionEvent e1, MotionEvent e2,
                                   float velocityX, float velocityY) {

                if (Math.abs(e1.getRawY() - e1.getRawY()) > 100) {

                    Toast.makeText(GA.this, "不能这样滑哦",
                            Toast.LENGTH_SHORT).show();
                    return true;

                }
                if (Math.abs(velocityX) < 100) {

                    Toast.makeText(GA.this, "滑动的太慢了",
                            Toast.LENGTH_SHORT).show();
                    return true;

                }

                if (e2.getRawX() - e1.getRawX() > 200) {
                    Toast.makeText(GA.this, "往右滑",
                            Toast.LENGTH_SHORT).show();
                    return true;
                }

                if (e1.getRawX() - e2.getRawX() > 200) {
                    Toast.makeText(GA.this, "往左滑",
                            Toast.LENGTH_SHORT).show();
                    return true;
                }
                if (e2.getRawY() - e1.getRawY() > 200) {
                    Toast.makeText(GA.this, "往下滑",
                            Toast.LENGTH_SHORT).show();
                    return true;
                }

                if (e1.getRawY() - e2.getRawY() > 200) {
                    Toast.makeText(GA.this, "往上滑",
                            Toast.LENGTH_SHORT).show();
                    return true;
                }



                return super.onFling(e1, e2, velocityX, velocityY);
            };

        });
    }

    public boolean onTouchEvent(MotionEvent event) {
        mDector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
}
